Get ACS data

Suppose you wish to tabulate ACS one-year 2019 data for estimates of total people by race and ethnicity, as provided in table B03002 by PSRC counties. You would use the following function call:

get_acs_recs(geography = 'county',
             table.names = 'B03002',
             years = 2019,
             acs.type = 'acs1')
## # A tibble: 105 x 11
##    GEOID name  state variable estimate   moe label concept census_geography
##    <chr> <chr> <chr> <chr>       <dbl> <dbl> <chr> <chr>   <chr>           
##  1 53033 King~ Wash~ B03002_~  2252782    NA Esti~ HISPAN~ County          
##  2 53033 King~ Wash~ B03002_~  2030140    NA Esti~ HISPAN~ County          
##  3 53033 King~ Wash~ B03002_~  1302544  3208 Esti~ HISPAN~ County          
##  4 53033 King~ Wash~ B03002_~   147822  4678 Esti~ HISPAN~ County          
##  5 53033 King~ Wash~ B03002_~    13321  1990 Esti~ HISPAN~ County          
##  6 53033 King~ Wash~ B03002_~   424590  7085 Esti~ HISPAN~ County          
##  7 53033 King~ Wash~ B03002_~    15702  1831 Esti~ HISPAN~ County          
##  8 53033 King~ Wash~ B03002_~     6574  3281 Esti~ HISPAN~ County          
##  9 53033 King~ Wash~ B03002_~   119587  8804 Esti~ HISPAN~ County          
## 10 53033 King~ Wash~ B03002_~     2639  1744 Esti~ HISPAN~ County          
## # ... with 95 more rows, and 2 more variables: acs_type <chr>, year <dbl>

Default and custom arguments

By default, without specifying any counties, the jurisdictions returned will be King, Kitsap, Pierce, and Snohomish Counties. Use ?get_acs_recs() for other default values implemented in this function.

To retrieve non-PSRC counties or a subset of the default counties, use the counties argument and provide a vector of counties (e.g. counties = c("King", "Thurston")). Do not use the fips argument as that is reserved for MSA or place geographies.

Get Census data

The get_decennial_recs() to generate Decennial Census tables operates similarly to the get_acs_recs(). If you wanted to retrieve housing units and total population by MSA, you would call the following:

get_decennial_recs(geography = 'msa',
                   table_codes = c("H001", "P001"),
                   year = 2010,
                   fips = c('42660', "28420"))
## # A tibble: 4 x 6
##   GEOID NAME                               variable   value label concept       
##   <chr> <chr>                              <chr>      <dbl> <chr> <chr>         
## 1 28420 Kennewick-Pasco-Richland, WA Metr~ H001001    93041 Total HOUSING UNITS 
## 2 42660 Seattle-Tacoma-Bellevue, WA Metro~ H001001  1463295 Total HOUSING UNITS 
## 3 28420 Kennewick-Pasco-Richland, WA Metr~ P001001   253340 Total TOTAL POPULAT~
## 4 42660 Seattle-Tacoma-Bellevue, WA Metro~ P001001  3439809 Total TOTAL POPULAT~

Note: the table names are padded with 0s, so you call “H001” as opposed to “H1” as you would in Elmer. Only SF1 tables are currently implemented.

Make a map of ACS data by tract

Let’s say you want to create a map of the tracts in the region for one variable. You can use the function create_tract_map(). Here’s an example, mapping non-Hispanic Black or African American population alone by tract:

library(sf)
library(dplyr)

tract.big.tbl <- get_acs_recs(geography ='tract', 
                              table.names = 'B03002',
                              years = 2019)

tract.tbl <- tract.big.tbl %>% 
  filter(label=='Estimate!!Total:!!Not Hispanic or Latino:!!Black or African American alone')

gdb.nm <- "MSSQL:server=AWS-PROD-SQL\\Sockeye; database=ElmerGeo; trusted_connection=yes"
spn <-  2285
tract_layer_name <- "dbo.tract2010_nowater"
tract.lyr <- st_read(gdb.nm, tract_layer_name, crs = spn, quiet = TRUE)

create_tract_map(tract.tbl, 
                 tract.lyr, 
                 map.title='Black, non-Hispanic Population',
                 map.title.position='topleft', 
                 legend.title='Black, Non-Hispanic Population',
                 legend.subtitle='by Census Tract')